package com.futuristik.objects;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;

public class StickyFloor extends FloorObject {

	public StickyFloor(float x, float y, float width, float angle) {
		super(x, y, width, angle);
		
		mu = 100f;

		floorTexture = new Texture(Gdx.files.internal("data/obj/stickyfloor.png"));
		floorTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
        floorTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
		Vector2 v1 = new Vector2(x, y);
		Vector2 v2 = new Vector2(MathUtils.cos(angle) * width, MathUtils.sin(angle) * width);
		Vector2 v3 = new Vector2(-MathUtils.sin(angle) * height, MathUtils.cos(angle) * height);
		
		floorTextureMesh = new Mesh(true, 4, 4, new VertexAttribute(Usage.Position, 3, "a_position"), 
				new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
		
		floorTextureMesh.setVertices(verticesForUnscaledTexture(floorTexture, new float[] { 
				v1.cpy().sub(v2).sub(v3).x, v1.cpy().sub(v2).sub(v3).y,
                v1.cpy().add(v2).sub(v3).x, v1.cpy().add(v2).sub(v3).y,
                v1.cpy().sub(v2).add(v3).x, v1.cpy().sub(v2).add(v3).y,
                v1.cpy().add(v2).add(v3).x, v1.cpy().add(v2).add(v3).y,
               })); 
		
		floorTextureMesh.setIndices(new short[] { 0, 1, 2, 3 });
	}
}
